*** NOTE:  This do-file performs the MSA-level purchase FRM specifications in Table 6a. ***
***        If an MSA's specfication did not converge using the MNL model with unobseved ***
***        heterogeneity in this do-file, that MSA's analysis was performed using the   ***
***        constant heterogeneity weight approach found in the do-file named "Table 6   ***
***        constant mass point -- purch_frm.                                            ***



log using "C:\Documents and Settings\morgan.rose\My Documents\Foreclosure\Geographic Consistency\Stata\Stata Logs\20101016 mymlogit_uh_lf by msa -- full size -- purch_frm.log", replace



program mymlogit_uh_lf
	version 10.1
	args lnf bxj1 bxj2 loc_j1_l1 loc_j1_l2 mass_point loc_j2_l1 loc_j2_l2
	tempvar denom_l1 denom_l2 mass_prob_l1 mass_prob_l2
	quietly generate double `denom_l1' = 1 + exp(`bxj1' + `loc_j1_l1') + exp(`bxj2' + `loc_j2_l1')
	quietly generate double `denom_l2' = 1 + exp(`bxj1' + `loc_j1_l2') + exp(`bxj2' + `loc_j2_l2')

	quietly generate double `mass_prob_l1' = exp(`mass_point') / (1 + exp(`mass_point'))
	quietly generate double `mass_prob_l2' = 1 / (1 + exp(`mass_point'))


	quietly replace `lnf' = ln((`mass_prob_l1'*(1/`denom_l1')) + (`mass_prob_l2'*(1/`denom_l2'))) if $ML_y1 == 0
	quietly replace `lnf' = ln((`mass_prob_l1'*(exp(`bxj1' + `loc_j1_l1')/`denom_l1')) + (`mass_prob_l2'*(exp(`bxj1' + `loc_j1_l2')/`denom_l2'))) if $ML_y1 == 1
	quietly replace `lnf' = ln((`mass_prob_l1'*(exp(`bxj2' + `loc_j2_l1')/`denom_l1')) + (`mass_prob_l2'*(exp(`bxj2' + `loc_j2_l2')/`denom_l2'))) if $ML_y1 == 2
end



*****************
*** Atlanta   ***
*** purch_frm ***
*****************

use "C:\Documents and Settings\morgan.rose\My Documents\Foreclosure\Geographic Consistency\Stata\Stata Data\MSA Level\Atlanta\atlanta_both_purch_frm generated.dta", clear

*** Generating matrix of starting values using mlogit ***
mlogit outcome_a prepay_pen prepay_pen_end balloon lownodoc fico cltv refi_premium ageofloan ageofloan_2 rel_loan_size chg_unempl var_hpi var_fixed vint2003 vint2004 vint2005 vint2006 if outsample_a != 1 & fico > 0 & cltv != 0 & balance != 0, cluster(loan_id_num)
outreg2 using "C:\Documents and Settings\morgan.rose\My Documents\Foreclosure\Geographic consistency\Stata\Stata Outregs\20101016 mlogit by MSA full size purch_frm.txt", replace onecol text bracket(se) e(all)
do "C:\Documents and Settings\morgan.rose\My Documents\Foreclosure\Geographic Consistency\Stata\Stata Do-files\mymlogit_uh_lf\creating starter matrix for mymlogit_uh_lf.do"

*** Running mymlogit_uh_lf ***
ml model lf mymlogit_uh_lf (default: outcome_a = prepay_pen prepay_pen_end balloon lownodoc fico cltv refi_premium ageofloan ageofloan_2 rel_loan_size chg_unempl var_hpi var_fixed vint2003 vint2004 vint2005 vint2006, noconstant) (payoff: prepay_pen prepay_pen_end balloon lownodoc fico cltv refi_premium ageofloan ageofloan_2 rel_loan_size chg_unempl var_hpi var_fixed vint2003 vint2004 vint2005 vint2006, noconstant) (default_const1:) (default_const2:) (prob_coeff1:) (payoff_const1:) (payoff_const2:) if outsample_a != 1 & fico > 0 & cltv != 0 & balance != 0, cluster(loan_id_num)
*ml check
ml init starter, copy
ml maximize, iterate(1000) difficult
outreg2 using "C:\Documents and Settings\morgan.rose\My Documents\Foreclosure\Geographic consistency\Stata\Stata Outregs\20101016 mymlogit_uh_lf by MSA full size purch_frm.txt", replace onecol text bracket(se) e(all)
*ml graph






*****************
*** Baltimore ***
*** purch_frm ***
*****************

use "C:\Documents and Settings\morgan.rose\My Documents\Foreclosure\Geographic Consistency\Stata\Stata Data\MSA Level\Baltimore\baltimore_both_purch_frm generated.dta", clear

*** Generating matrix of starting values using mlogit ***
mlogit outcome_a prepay_pen prepay_pen_end balloon lownodoc fico cltv refi_premium ageofloan ageofloan_2 rel_loan_size chg_unempl var_hpi var_fixed vint2003 vint2004 vint2005 vint2006 if outsample_a != 1 & fico > 0 & cltv != 0 & balance != 0, cluster(loan_id_num)
outreg2 using "C:\Documents and Settings\morgan.rose\My Documents\Foreclosure\Geographic consistency\Stata\Stata Outregs\20101016 mlogit by MSA full size purch_frm.txt", append onecol text bracket(se) e(all)
do "C:\Documents and Settings\morgan.rose\My Documents\Foreclosure\Geographic Consistency\Stata\Stata Do-files\mymlogit_uh_lf\creating starter matrix for mymlogit_uh_lf.do"

*** Running mymlogit_uh_lf ***
ml model lf mymlogit_uh_lf (default: outcome_a = prepay_pen prepay_pen_end balloon lownodoc fico cltv refi_premium ageofloan ageofloan_2 rel_loan_size chg_unempl var_hpi var_fixed vint2003 vint2004 vint2005 vint2006, noconstant) (payoff: prepay_pen prepay_pen_end balloon lownodoc fico cltv refi_premium ageofloan ageofloan_2 rel_loan_size chg_unempl var_hpi var_fixed vint2003 vint2004 vint2005 vint2006, noconstant) (default_const1:) (default_const2:) (prob_coeff1:) (payoff_const1:) (payoff_const2:) if outsample_a != 1 & fico > 0 & cltv != 0 & balance != 0, cluster(loan_id_num)
*ml check
ml init starter, copy
ml maximize, iterate(1000) difficult
outreg2 using "C:\Documents and Settings\morgan.rose\My Documents\Foreclosure\Geographic consistency\Stata\Stata Outregs\20101016 mymlogit_uh_lf by MSA full size purch_frm.txt", append onecol text bracket(se) e(all)
*ml graph






*****************
*** Chicago   ***
*** purch_frm ***
*****************

use "C:\Documents and Settings\morgan.rose\My Documents\Foreclosure\Geographic Consistency\Stata\Stata Data\MSA Level\Chicago\chicago_both_purch_frm generated.dta", clear

*** Generating matrix of starting values using mlogit ***
mlogit outcome_a prepay_pen prepay_pen_end balloon lownodoc fico cltv refi_premium ageofloan ageofloan_2 rel_loan_size chg_unempl var_hpi var_fixed vint2003 vint2004 vint2005 vint2006 if outsample_a != 1 & fico > 0 & cltv != 0 & balance != 0, cluster(loan_id_num)
outreg2 using "C:\Documents and Settings\morgan.rose\My Documents\Foreclosure\Geographic consistency\Stata\Stata Outregs\20101016 mlogit by MSA full size purch_frm.txt", append onecol text bracket(se) e(all)
do "C:\Documents and Settings\morgan.rose\My Documents\Foreclosure\Geographic Consistency\Stata\Stata Do-files\mymlogit_uh_lf\creating starter matrix for mymlogit_uh_lf.do"

*** Running mymlogit_uh_lf ***
ml model lf mymlogit_uh_lf (default: outcome_a = prepay_pen prepay_pen_end balloon lownodoc fico cltv refi_premium ageofloan ageofloan_2 rel_loan_size chg_unempl var_hpi var_fixed vint2003 vint2004 vint2005 vint2006, noconstant) (payoff: prepay_pen prepay_pen_end balloon lownodoc fico cltv refi_premium ageofloan ageofloan_2 rel_loan_size chg_unempl var_hpi var_fixed vint2003 vint2004 vint2005 vint2006, noconstant) (default_const1:) (default_const2:) (prob_coeff1:) (payoff_const1:) (payoff_const2:) if outsample_a != 1 & fico > 0 & cltv != 0 & balance != 0, cluster(loan_id_num)
*ml check
ml init starter, copy
ml maximize, iterate(1000) difficult
outreg2 using "C:\Documents and Settings\morgan.rose\My Documents\Foreclosure\Geographic consistency\Stata\Stata Outregs\20101016 mymlogit_uh_lf by MSA full size purch_frm.txt", append onecol text bracket(se) e(all)
*ml graph






******************
*** LosAngeles ***
*** purch_frm  ***
******************

use "C:\Documents and Settings\morgan.rose\My Documents\Foreclosure\Geographic Consistency\Stata\Stata Data\MSA Level\LosAngeles\losangeles_both_purch_frm generated.dta", clear

*** Generating matrix of starting values using mlogit ***
mlogit outcome_a prepay_pen prepay_pen_end balloon lownodoc fico cltv refi_premium ageofloan ageofloan_2 rel_loan_size chg_unempl var_hpi var_fixed vint2003 vint2004 vint2005 vint2006 if outsample_a != 1 & fico > 0 & cltv != 0 & balance != 0, cluster(loan_id_num)
outreg2 using "C:\Documents and Settings\morgan.rose\My Documents\Foreclosure\Geographic consistency\Stata\Stata Outregs\20101016 mlogit by MSA full size purch_frm.txt", append onecol text bracket(se) e(all)
do "C:\Documents and Settings\morgan.rose\My Documents\Foreclosure\Geographic Consistency\Stata\Stata Do-files\mymlogit_uh_lf\creating starter matrix for mymlogit_uh_lf.do"

*** Running mymlogit_uh_lf ***
ml model lf mymlogit_uh_lf (default: outcome_a = prepay_pen prepay_pen_end balloon lownodoc fico cltv refi_premium ageofloan ageofloan_2 rel_loan_size chg_unempl var_hpi var_fixed vint2003 vint2004 vint2005 vint2006, noconstant) (payoff: prepay_pen prepay_pen_end balloon lownodoc fico cltv refi_premium ageofloan ageofloan_2 rel_loan_size chg_unempl var_hpi var_fixed vint2003 vint2004 vint2005 vint2006, noconstant) (default_const1:) (default_const2:) (prob_coeff1:) (payoff_const1:) (payoff_const2:) if outsample_a != 1 & fico > 0 & cltv != 0 & balance != 0, cluster(loan_id_num)
*ml check
ml init starter, copy
ml maximize, iterate(1000) difficult
outreg2 using "C:\Documents and Settings\morgan.rose\My Documents\Foreclosure\Geographic consistency\Stata\Stata Outregs\20101016 mymlogit_uh_lf by MSA full size purch_frm.txt", append onecol text bracket(se) e(all)
*ml graph






*****************
*** Miami     ***
*** purch_frm ***
*****************

use "C:\Documents and Settings\morgan.rose\My Documents\Foreclosure\Geographic Consistency\Stata\Stata Data\MSA Level\Miami\miami_both_purch_frm generated.dta", clear

*** Generating matrix of starting values using mlogit ***
mlogit outcome_a prepay_pen prepay_pen_end balloon lownodoc fico cltv refi_premium ageofloan ageofloan_2 rel_loan_size chg_unempl var_hpi var_fixed vint2003 vint2004 vint2005 vint2006 if outsample_a != 1 & fico > 0 & cltv != 0 & balance != 0, cluster(loan_id_num)
outreg2 using "C:\Documents and Settings\morgan.rose\My Documents\Foreclosure\Geographic consistency\Stata\Stata Outregs\20101016 mlogit by MSA full size purch_frm.txt", append onecol text bracket(se) e(all)
do "C:\Documents and Settings\morgan.rose\My Documents\Foreclosure\Geographic Consistency\Stata\Stata Do-files\mymlogit_uh_lf\creating starter matrix for mymlogit_uh_lf.do"

*** Running mymlogit_uh_lf ***
ml model lf mymlogit_uh_lf (default: outcome_a = prepay_pen prepay_pen_end balloon lownodoc fico cltv refi_premium ageofloan ageofloan_2 rel_loan_size chg_unempl var_hpi var_fixed vint2003 vint2004 vint2005 vint2006, noconstant) (payoff: prepay_pen prepay_pen_end balloon lownodoc fico cltv refi_premium ageofloan ageofloan_2 rel_loan_size chg_unempl var_hpi var_fixed vint2003 vint2004 vint2005 vint2006, noconstant) (default_const1:) (default_const2:) (prob_coeff1:) (payoff_const1:) (payoff_const2:) if outsample_a != 1 & fico > 0 & cltv != 0 & balance != 0, cluster(loan_id_num)
*ml check
ml init starter, copy
ml maximize, iterate(1000) difficult
outreg2 using "C:\Documents and Settings\morgan.rose\My Documents\Foreclosure\Geographic consistency\Stata\Stata Outregs\20101016 mymlogit_uh_lf by MSA full size purch_frm.txt", append onecol text bracket(se) e(all)
*ml graph






*******************
*** Minneapolis ***
*** purch_frm   ***
*******************

use "C:\Documents and Settings\morgan.rose\My Documents\Foreclosure\Geographic Consistency\Stata\Stata Data\MSA Level\Minneapolis\minneapolis_both_purch_frm generated.dta", clear

*** Generating matrix of starting values using mlogit ***
mlogit outcome_a prepay_pen prepay_pen_end balloon lownodoc fico cltv refi_premium ageofloan ageofloan_2 rel_loan_size chg_unempl var_hpi var_fixed vint2003 vint2004 vint2005 vint2006 if outsample_a != 1 & fico > 0 & cltv != 0 & balance != 0, cluster(loan_id_num)
outreg2 using "C:\Documents and Settings\morgan.rose\My Documents\Foreclosure\Geographic consistency\Stata\Stata Outregs\20101016 mlogit by MSA full size purch_frm.txt", append onecol text bracket(se) e(all)
do "C:\Documents and Settings\morgan.rose\My Documents\Foreclosure\Geographic Consistency\Stata\Stata Do-files\mymlogit_uh_lf\creating starter matrix for mymlogit_uh_lf.do"

*** Running mymlogit_uh_lf ***
ml model lf mymlogit_uh_lf (default: outcome_a = prepay_pen prepay_pen_end balloon lownodoc fico cltv refi_premium ageofloan ageofloan_2 rel_loan_size chg_unempl var_hpi var_fixed vint2003 vint2004 vint2005 vint2006, noconstant) (payoff: prepay_pen prepay_pen_end balloon lownodoc fico cltv refi_premium ageofloan ageofloan_2 rel_loan_size chg_unempl var_hpi var_fixed vint2003 vint2004 vint2005 vint2006, noconstant) (default_const1:) (default_const2:) (prob_coeff1:) (payoff_const1:) (payoff_const2:) if outsample_a != 1 & fico > 0 & cltv != 0 & balance != 0, cluster(loan_id_num)
*ml check
ml init starter, copy
ml maximize, iterate(1000) difficult
outreg2 using "C:\Documents and Settings\morgan.rose\My Documents\Foreclosure\Geographic consistency\Stata\Stata Outregs\20101016 mymlogit_uh_lf by MSA full size purch_frm.txt", append onecol text bracket(se) e(all)
*ml graph






*****************
*** NewYork   ***
*** purch_frm ***
*****************

use "C:\Documents and Settings\morgan.rose\My Documents\Foreclosure\Geographic Consistency\Stata\Stata Data\MSA Level\NewYork\newyork_both_purch_frm generated.dta", clear

*** Generating matrix of starting values using mlogit ***
mlogit outcome_a prepay_pen prepay_pen_end balloon lownodoc fico cltv refi_premium ageofloan ageofloan_2 rel_loan_size chg_unempl var_hpi var_fixed vint2003 vint2004 vint2005 vint2006 if outsample_a != 1 & fico > 0 & cltv != 0 & balance != 0, cluster(loan_id_num)
outreg2 using "C:\Documents and Settings\morgan.rose\My Documents\Foreclosure\Geographic consistency\Stata\Stata Outregs\20101016 mlogit by MSA full size purch_frm.txt", append onecol text bracket(se) e(all)
do "C:\Documents and Settings\morgan.rose\My Documents\Foreclosure\Geographic Consistency\Stata\Stata Do-files\mymlogit_uh_lf\creating starter matrix for mymlogit_uh_lf.do"

*** Running mymlogit_uh_lf ***
ml model lf mymlogit_uh_lf (default: outcome_a = prepay_pen prepay_pen_end balloon lownodoc fico cltv refi_premium ageofloan ageofloan_2 rel_loan_size chg_unempl var_hpi var_fixed vint2003 vint2004 vint2005 vint2006, noconstant) (payoff: prepay_pen prepay_pen_end balloon lownodoc fico cltv refi_premium ageofloan ageofloan_2 rel_loan_size chg_unempl var_hpi var_fixed vint2003 vint2004 vint2005 vint2006, noconstant) (default_const1:) (default_const2:) (prob_coeff1:) (payoff_const1:) (payoff_const2:) if outsample_a != 1 & fico > 0 & cltv != 0 & balance != 0, cluster(loan_id_num)
*ml check
ml init starter, copy
ml maximize, iterate(1000) difficult
outreg2 using "C:\Documents and Settings\morgan.rose\My Documents\Foreclosure\Geographic consistency\Stata\Stata Outregs\20101016 mymlogit_uh_lf by MSA full size purch_frm.txt", append onecol text bracket(se) e(all)
*ml graph






*****************
*** Phoenix   ***
*** purch_frm ***
*****************

use "C:\Documents and Settings\morgan.rose\My Documents\Foreclosure\Geographic Consistency\Stata\Stata Data\MSA Level\Phoenix\phoenix_both_purch_frm generated.dta", clear

*** Generating matrix of starting values using mlogit ***
mlogit outcome_a prepay_pen prepay_pen_end balloon lownodoc fico cltv refi_premium ageofloan ageofloan_2 rel_loan_size chg_unempl var_hpi var_fixed vint2003 vint2004 vint2005 vint2006 if outsample_a != 1 & fico > 0 & cltv != 0 & balance != 0, cluster(loan_id_num)
outreg2 using "C:\Documents and Settings\morgan.rose\My Documents\Foreclosure\Geographic consistency\Stata\Stata Outregs\20101016 mlogit by MSA full size purch_frm.txt", append onecol text bracket(se) e(all)
do "C:\Documents and Settings\morgan.rose\My Documents\Foreclosure\Geographic Consistency\Stata\Stata Do-files\mymlogit_uh_lf\creating starter matrix for mymlogit_uh_lf.do"

*** Running mymlogit_uh_lf ***
ml model lf mymlogit_uh_lf (default: outcome_a = prepay_pen prepay_pen_end balloon lownodoc fico cltv refi_premium ageofloan ageofloan_2 rel_loan_size chg_unempl var_hpi var_fixed vint2003 vint2004 vint2005 vint2006, noconstant) (payoff: prepay_pen prepay_pen_end balloon lownodoc fico cltv refi_premium ageofloan ageofloan_2 rel_loan_size chg_unempl var_hpi var_fixed vint2003 vint2004 vint2005 vint2006, noconstant) (default_const1:) (default_const2:) (prob_coeff1:) (payoff_const1:) (payoff_const2:) if outsample_a != 1 & fico > 0 & cltv != 0 & balance != 0, cluster(loan_id_num)
*ml check
ml init starter, copy
ml maximize, iterate(1000) difficult
outreg2 using "C:\Documents and Settings\morgan.rose\My Documents\Foreclosure\Geographic consistency\Stata\Stata Outregs\20101016 mymlogit_uh_lf by MSA full size purch_frm.txt", append onecol text bracket(se) e(all)
*ml graph






******************
*** Pittsburgh ***
*** purch_frm  ***
******************

use "C:\Documents and Settings\morgan.rose\My Documents\Foreclosure\Geographic Consistency\Stata\Stata Data\MSA Level\Pittsburgh\pittsburgh_both_purch_frm generated.dta", clear

*** Generating matrix of starting values using mlogit ***
mlogit outcome_a prepay_pen prepay_pen_end balloon lownodoc fico cltv refi_premium ageofloan ageofloan_2 rel_loan_size chg_unempl var_hpi var_fixed vint2003 vint2004 vint2005 vint2006 if outsample_a != 1 & fico > 0 & cltv != 0 & balance != 0, cluster(loan_id_num)
outreg2 using "C:\Documents and Settings\morgan.rose\My Documents\Foreclosure\Geographic consistency\Stata\Stata Outregs\20101016 mlogit by MSA full size purch_frm.txt", append onecol text bracket(se) e(all)
do "C:\Documents and Settings\morgan.rose\My Documents\Foreclosure\Geographic Consistency\Stata\Stata Do-files\mymlogit_uh_lf\creating starter matrix for mymlogit_uh_lf.do"

*** Running mymlogit_uh_lf ***
ml model lf mymlogit_uh_lf (default: outcome_a = prepay_pen prepay_pen_end balloon lownodoc fico cltv refi_premium ageofloan ageofloan_2 rel_loan_size chg_unempl var_hpi var_fixed vint2003 vint2004 vint2005 vint2006, noconstant) (payoff: prepay_pen prepay_pen_end balloon lownodoc fico cltv refi_premium ageofloan ageofloan_2 rel_loan_size chg_unempl var_hpi var_fixed vint2003 vint2004 vint2005 vint2006, noconstant) (default_const1:) (default_const2:) (prob_coeff1:) (payoff_const1:) (payoff_const2:) if outsample_a != 1 & fico > 0 & cltv != 0 & balance != 0, cluster(loan_id_num)
*ml check
ml init starter, copy
ml maximize, iterate(1000) difficult
outreg2 using "C:\Documents and Settings\morgan.rose\My Documents\Foreclosure\Geographic consistency\Stata\Stata Outregs\20101016 mymlogit_uh_lf by MSA full size purch_frm.txt", append onecol text bracket(se) e(all)
*ml graph






******************
*** SanAntonio ***
*** purch_frm  ***
******************

use "C:\Documents and Settings\morgan.rose\My Documents\Foreclosure\Geographic Consistency\Stata\Stata Data\MSA Level\SanAntonio\sanantonio_both_purch_frm generated.dta", clear

*** Generating matrix of starting values using mlogit ***
mlogit outcome_a prepay_pen prepay_pen_end balloon lownodoc fico cltv refi_premium ageofloan ageofloan_2 rel_loan_size chg_unempl var_hpi var_fixed vint2003 vint2004 vint2005 vint2006 if outsample_a != 1 & fico > 0 & cltv != 0 & balance != 0, cluster(loan_id_num)
outreg2 using "C:\Documents and Settings\morgan.rose\My Documents\Foreclosure\Geographic consistency\Stata\Stata Outregs\20101016 mlogit by MSA full size purch_frm.txt", append onecol text bracket(se) e(all)
do "C:\Documents and Settings\morgan.rose\My Documents\Foreclosure\Geographic Consistency\Stata\Stata Do-files\mymlogit_uh_lf\creating starter matrix for mymlogit_uh_lf.do"

*** Running mymlogit_uh_lf ***
ml model lf mymlogit_uh_lf (default: outcome_a = prepay_pen prepay_pen_end balloon lownodoc fico cltv refi_premium ageofloan ageofloan_2 rel_loan_size chg_unempl var_hpi var_fixed vint2003 vint2004 vint2005 vint2006, noconstant) (payoff: prepay_pen prepay_pen_end balloon lownodoc fico cltv refi_premium ageofloan ageofloan_2 rel_loan_size chg_unempl var_hpi var_fixed vint2003 vint2004 vint2005 vint2006, noconstant) (default_const1:) (default_const2:) (prob_coeff1:) (payoff_const1:) (payoff_const2:) if outsample_a != 1 & fico > 0 & cltv != 0 & balance != 0, cluster(loan_id_num)
*ml check
ml init starter, copy
ml maximize, iterate(1000) difficult
outreg2 using "C:\Documents and Settings\morgan.rose\My Documents\Foreclosure\Geographic consistency\Stata\Stata Outregs\20101016 mymlogit_uh_lf by MSA full size purch_frm.txt", append onecol text bracket(se) e(all)
*ml graph



program drop mymlogit_uh_lf



log close



clear



